package br.com.sisnema.aula2.adapter;

import java.util.List;

import br.com.sisnema.aula2.R;
import br.com.sisnema.aula2.vo.ClienteVO;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ClienteAdapter extends BaseAdapter{

	private List<ClienteVO> lista = null;
	private Context ctx = null;
	
	public ClienteAdapter(Context ctx, List<ClienteVO> lista){
		this.lista = lista;
		this.ctx = ctx;
	}
	
	@Override
	public int getCount() {
		return lista.size();
	}

	@Override
	public Object getItem(int position) {
		return lista.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		
		ClienteVO vo = lista.get(position);
		
		
		LayoutInflater layout = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View v = layout.inflate(R.layout.listar, null);
		
		TextView txvId = (TextView)v.findViewById(R.id.txvID);
		txvId.setText(String.valueOf(vo.getId()));
		
		if(vo.getId() == 1){
			txvId.setBackgroundColor(Color.RED);
		}
		
		TextView txvNome = (TextView)v.findViewById(R.id.txvNome);
		txvNome.setText(String.valueOf(vo.getId()));
		
		TextView txvEmail = (TextView)v.findViewById(R.id.txvEmail);
		txvEmail.setText(String.valueOf(vo.getId()));
		
		
		return v;
	}

}
